<template>
  <div class="main-container" :style="{background: `url('${bg}')`}">
    <div class="hotal-img">
      <!-- vant 轮播 -->
      <van-swipe class="hotel-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(image, index) in hotelDetail.images" :key="index">
          <img :src="image" alt="" style="width: 100%; height: 400px; object-fit: cover; display: block;">
        </van-swipe-item>
      </van-swipe>
      <div class="name" :style="{background: `url('${namebg}')`}">
        <h3>{{ hotelDetail.custname }}</h3>
        <div class="desc">{{ hotelDetail.notes }}</div>
      </div>
    </div>
    <div class="address">
      {{ hotelDetail.address }}
      <div>
        <a @click="handleOpen" class="phone">
          <img src="@/assets/img/nav.png" alt="">
        </a>
        <a class="phone" @click="handleToPhone">
          <img src="@/assets/img/phone.png" alt="">
        </a>
      </div>
    </div>

    <!-- 重点事项 -->
    <div class="important-info">
      <h3>重点事项</h3>
      <p>{{ hotelDetail.taxno }}</p>
    </div>

    <!-- 推荐套餐 -->
    <div class="package-section">
      <h3 class="section-title">推荐套餐</h3>

      <!-- 套餐项 -->
      <div class="package-item" v-for="(item, index) in packageList" :key="index">
        <div class="package-img">
          <img :src="item.image" alt="">
        </div>
        <div class="package-info">
          <div class="package-name">{{ item.name }}</div>
          <div class="package-rule">
            <!-- <span class="rule-icon">ⓘ</span> -->
            <!-- <span class="rule-text">使用规则：{{ item.rule }}</span> -->
          </div>
          <div class="package-detail">
            <van-dialog v-model:show="showRemark" title="套餐详情">
              <div style="padding: 20px; height: 60vh; overflow: auto;" v-html="currentRemark"></div>
            </van-dialog>
            <span @click="showRemarkDialog(item.remark)">点击查看套餐详情 ›</span>
          </div>
        </div>
        <div class="package-price">
          <span>{{ item.price }}</span>
        </div>
      </div>
    </div>
    <!-- Update component usage to use v-model -->
    <position-navigation :isShowSheet="isShowSheet" :selectedPoint="hotelDetail"  @close="handleClose"></position-navigation>

  </div>
</template>

<script setup>
import bg from '@/assets/img/bg.png'
import namebg from '@/assets/img/name.png'
import positionNavigation from '@/components/positionNavigation.vue'
import { ref, onMounted, reactive } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { festivalApi } from '@/api'
const router = useRouter()
const route = useRoute()
const isShowSheet = ref(false)
const packageList = reactive([])
const hotelDetail = reactive({
  custname: '',
  address: '',
  notes: '',
  images: []
})
const currentRemark = ref('')
const showRemark = ref(false)

const init = () => {
  const uid = localStorage.getItem('uid')
  const companyid = route.query.id
  festivalApi.getCompanyDetail({
    uid,
    companyid,
    pageNum: 1,
    pageSize: 1000
  }).then(res => {
    Object.assign(hotelDetail, res.data)
    // 处理图片路径
    hotelDetail.images = res.data.images.map(item =>
      window.APP_CONFIG?.apiBaseUrl + item
    )
  })

  festivalApi.getProductList({
    uid,
    companyid,
    pageNum: 1,
    pageSize: 1000
  }).then(res => {
    Object.assign(packageList, res.data)
    // // 处理图片路径
    packageList = res.data.map(item => {
      item.image = window.APP_CONFIG?.apiBaseUrl + item.images[0]
      return item
    })
    console.log(packageList)
  })
}
onMounted(() => {
  init()
})

const handleToPhone = () => {
  if (hotelDetail.contacttel == '') {
    showFailToast('暂无电话')
    return
  }
  window.location.href = `tel:${hotelDetail.contacttel}`
}

const handleClose = () => {
  isShowSheet.value = false
}
const handleOpen = () => {
  isShowSheet.value = true
}

const showRemarkDialog = (remark) => {
  currentRemark.value = remark
  showRemark.value = true
}
</script>

<style lang="less">
.main-container {
  height: 100vh;
  overflow: scroll;
  background-size: 100%;
  background-color: #f1f3f4;

  .hotal-img {
    width: 100%;
    position: relative;

    .name {
      position: absolute;
      bottom: 0;
      font-size: 12px;
      color: #fff;
      padding: 10px;
      background-size: contain;

      h3 {
        font-size: 14px;
        font-weight: bold;
        margin: 0;
        margin-bottom: 10px;
      }

      .desc {
        // 最多4行
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        font-size: 12px;
      }
    }
  }

  .address {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    padding: 10px;
    background-color: #fff;

    img {
      width: 28px;
      height: 28px;
      margin-left: 20px;
    }
  }

  // 重点事项样式
  .important-info {
    padding: 15px;
    background-color: #fff;

    h3 {
      color: #e54847;
      font-size: 14px;
      margin: 0 0 10px 0;
      font-weight: bold;
      position: relative;
      padding-left: 10px;

      &:before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 3px;
        height: 14px;
        background-color: #e54847;
      }
    }

    p {
      font-size: 12px;
      color: #666;
      margin: 0;
      line-height: 1.5;
    }
  }

  // 推荐套餐样式
  .package-section {
    margin-top: 10px;
    background-color: #fff;
    padding: 15px 0;

    .section-title {
      color: #333;
      font-size: 14px;
      margin: 0 0 15px 0;
      font-weight: bold;
      position: relative;
      padding-left: 25px;

      &:before {
        content: '';
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        width: 3px;
        height: 14px;
        background-color: #e54847;
      }
    }

    .package-item {
      display: flex;
      padding: 15px;
      border-bottom: 1px solid #f0f0f0;
      position: relative;

      &:last-child {
        border-bottom: none;
      }

      .package-img {
        width: 90px;
        height: 90px;
        position: relative;
        margin-right: 10px;
        border-radius: 4px;
        overflow: hidden;

        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }

        .image-count {
          position: absolute;
          right: 5px;
          bottom: 5px;
          background-color: rgba(0, 0, 0, 0.6);
          color: #fff;
          font-size: 10px;
          padding: 2px 5px;
          border-radius: 10px;
        }
      }

      .package-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .package-name {
          font-size: 14px;
          font-weight: bold;
          color: #333;
          width: 75%;
        }

        .package-rule {
          font-size: 12px;
          color: #999;
          margin: 5px 0;
          display: flex;
          align-items: center;

          .rule-icon {
            color: #999;
            margin-right: 5px;
          }

          .rule-text {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 200px;
          }
        }

        .package-detail {
          font-size: 12px;
          color: #666;

          span {
            display: inline-block;
            position: relative;
          }
        }
      }

      .package-price {
        position: absolute;
        right: 15px;
        top: 15px;
        color: #e54847;
        font-size: 14px;
        font-weight: bold;
      }
    }
  }
}
</style>
